<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增字典类型</title>
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--公用样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/comment.css">
    <!--页面样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/style.css">
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/extended.css">
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
</head>
<body class="whitebg">


<div class="layui-form-item" style="padding: 20px 10px 20px 40px">
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>排序</label>
        <div class="layui-input-inline">
            <input type="number" name="badtIndex" id="badtIndex" lay-verify="badtIndex" autocomplete="off" class="fl" placeholder="请输入序号">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>编号</label>
        <div class="layui-input-inline">
            <input type="text" name="badtCode" id="badtCode" lay-verify="dictTypeCode" autocomplete="off" class="fl" placeholder="请输入字典编号">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>名称</label>
        <div class="layui-input-inline">
            <input type="text" name="badtName" id="badtName" lay-verify="dictTypeCode" autocomplete="off" class="fl" placeholder="请输入字典名称">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>科室代码</label>
        <div class="layui-input-inline">
            <input type="text" name="badtGroupid" id="badtGroupid" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入科室代码">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级1</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel1" id="badtLevel1" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级1">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级2</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel2" id="badtLevel2" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级2">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级3</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel3" id="badtLevel3" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级3">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级4</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel4" id="badtLevel4" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级4">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级5</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel5" id="badtLevel5" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级5">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级6</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel6" id="badtLevel6" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级6">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级7</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel7" id="badtLevel7" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级7">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>等级8</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel8" id="badtLevel8" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入等级8">
        </div>
    </div>
    <div class="layui-inline" id="sc">
        <label class="layui-form-label"><span class="red">*</span>允许上传的角色</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel11" id="badtLevel11" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="允许上传的角色">
        </div>
    </div>
    <div class="layui-inline" id="bj">
        <label class="layui-form-label"><span class="red">*</span>允许编辑的角色</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel13" id="badtLevel13" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="允许编辑的角色">
        </div>
    </div>
    <div class="layui-inline" id="dc">
        <label class="layui-form-label"><span class="red">*</span>允许导出的角色</label>
        <div class="layui-input-inline">
            <input type="text" name="badtLevel14" id="badtLevel14" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="允许导出的角色">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label"><span class="red">*</span>备注</label>
        <div class="layui-input-inline">
            <input type="text" name="badtNote" id="badtNote" lay-verify="dictTypeName" autocomplete="off" class="fl" placeholder="请输入备注">
        </div>
    </div>
</div>

<div style="background-color: white;background-color: white;padding: 15px;text-align: center;position: fixed;bottom: 1px;width: 100%;">
    <button class="layui-btn layui-btn-sm" lay-filter="submitType" lay-submit type="button">添加</button>
    <button class="layui-btn layui-btn-primary layui-btn-sm" type="button" id="close">取消</button>
</div>

<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script>
    $.ready=function(){
        $("#sc").hide();
        $("#bj").hide();
        $("#dc").hide();
        if(localStorage.getItem("currDictTypeData")){
            var dictTypeData = JSON.parse(localStorage.getItem("currDictTypeData"));
            if(dictTypeData.dictTypecode=='WJ001'){
                $("#sc").show();
                $("#bj").show();
                $("#dc").show();
            }else if(dictTypeData.dictTypecode == 'FORMFILE001' || dictTypeData.dictTypecode == 'XMWJ001'
                || dictTypeData.dictTypecode == 'ITFIRST001'){
                //表单页面:
                var w = ($(parent.window).width()*0.4);
                var h = ($(parent.window).height()*0.8);
                $('#badtCode').on('click',function(){

                    if(dictTypeData.dictTypecode == 'XMWJ001'
                        || dictTypeData.dictTypecode == 'ITFIRST001'){
                        localStorage.setItem("movepageactiontype","2");
                    }else{
                        localStorage.setItem("movepageactiontype","3");
                    }
                    parent.layer.open({
                        type: 2,
                        title: false,
                        closeBtn: 0,
                        shade: 0.8,
                        area: [w+'px',h+'px'],
                        content: '/it/dic/showDicTree?id=',
                        success: function(layero, index){
                            movePage = index;
                        },
                        end: function () {
                            console.log("关闭了移动文件页面")
                            if(dictTypeData.dictTypecode == 'XMWJ001'
                                || dictTypeData.dictTypecode == 'ITFIRST001'){
                                var checkeddicnodesstr = localStorage.getItem('checkeddicnodes');
                                if(checkeddicnodesstr){
                                    var checkedDicNodes = JSON.parse(checkeddicnodesstr);
                                    console.log(checkedDicNodes);
                                    if(checkedDicNodes && checkedDicNodes.length>0){
                                        addOneDic(checkedDicNodes,0);
                                    }
                                }
                            }else{
                                $('#badtCode').val(localStorage.getItem('checkeditformfileid'));
                                $('#badtName').val(localStorage.getItem('checkeditformfilename'));
                                localStorage.removeItem('checkeditformfileid');
                                localStorage.removeItem('checkeditformfilename');
                            }
                        }
                    });
                })
                if(dictTypeData.dictTypecode == 'FORMFILE001'){
                    var codePa = $('#badtGroupid').parent();
                    codePa.empty();
                    $.ajax({
                        url: '/sys/dict/getListByTypeCode?badtTypecode=FFC001',
                        type: 'get',
                        dataType: 'json',
                        success: function(res){
                            console.log(res.data);
                            if(res.data && res.data.length > 0){
                                var select = $('<select id="badtGroupid"></select>');

                                $.each(res.data,function(i,e){
                                    select.append('<option value="'+e.badtCode+'">'+e.badtName+'</option>')
                                })
                                codePa.append(select);
                            }else{
                                parent.layer.msg('请先设置IT表单编号',{icon:2});
                                return ;
                            }
                        },
                    })
                }
            }
        }
    }
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        $('#close').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
        //监听提交

        form.on('submit(submitType)', function(data){
            if(!$('#badtCode').val()){
                layer.msg('请输入字典编号',{icon:2});
                return ;
            }
            if(!$('#badtName').val()){
                layer.msg('请输入字典名称',{icon:2});
                return ;
            }
            var json = {
                badtTypecode: localStorage.getItem("currentType"),
                badtCode: $('#badtCode').val(),
                badtIndex: $('#badtIndex').val(),
                badtName:  $('#badtName').val(),
                badtGroupid:  $('#badtGroupid').val(),
                badtLevel1:  $('#badtLevel1').val(),
                badtLevel2:  $('#badtLevel2').val(),
                badtLevel3:  $('#badtLevel3').val(),
                badtLevel4:  $('#badtLevel4').val(),
                badtLevel5:  $('#badtLevel5').val(),
                badtLevel11:  $('#badtLevel11').val(),
                badtLevel13:  $('#badtLevel13').val(),
                badtLevel14:  $('#badtLevel14').val(),
                badtNote:  $('#badtNote').val()
            }

            layerAjax('/sys/dict/addDictValue',json, '',
                function (d) {
                    if (d.flag == true) {
                        // parent.flushDictList();
                        parent.layer.msg('操作成功', {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.flushDictList();
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            return false;
        });
    });

    function addOneDic(dicts,ind){
        debugger;
        if(!dicts[ind]){
            return ;
        }
        if(ind == 0){
            var type = localStorage.getItem("currentType");
            if(type){
                layerAjax('/sys/dict/deleteDictByTypeCode',{dictTypeCode: type});
            }
        }
        var json = {
            badtTypecode: localStorage.getItem("currentType"),
            badtCode: dicts[ind].id,
            badtName:  dicts[ind].name
        }
        layerAjax('/sys/dict/addDictValue',json, '',
            function (d) {
                if (d.flag == true) {
                    if(ind == (dicts.length-1)){
                        parent.layer.msg('操作成功', {icon: 1});
                        localStorage.removeItem('checkeddicnodes');
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.flushDictList();
                    }
                } else {
                    layer.msg(d.msg, {icon: 2});
                }
            });
        if(ind < dicts.length){
            ind++;
            addOneDic(dicts,ind);
        }
    }

</script>
</body>
</html>